import { Singleton } from "../../utils/Singleton";
import { SceneBase } from "./SceneBase";


/**
 * 场景管理器
 */
export class SceneMgr extends Singleton {
    private _sceneMap: Map<string, SceneBase> = new Map();

    runningScene: string = ''

    registerScene(name: string, scene: SceneBase) {
        if (this._sceneMap.has(name)) {
            console.warn(`${name}---此场景已注册过`);
            return;
        }
        this._sceneMap.set(name, scene);
    }

    startScene(name: string, ...args: any[]) {
        if (!this._sceneMap.has(name)) {
            console.warn(`${name}---没有注册此场景 `);
            return;
        }
        if (this.runningScene && this._sceneMap.has(this.runningScene)) {
            this._sceneMap.get(this.runningScene).onExit();
        }
        this.runningScene = name;
        this._sceneMap.get(name).onEnter(...args);
    }
}
export const sceneMgr = SceneMgr.getInstance<SceneMgr>();